import { axios } from '@/utils/request'

const api = {
  agent: '/agents',
  agentLabel: '/agents/labels'
}

export function getAgentList (params) {
  return axios({
    url: api.agent,
    method: 'get',
    responseType: params.hasOwnProperty('export') && !params.hasOwnProperty('async') ? 'blob' : 'json', // 导出 下载
    params
  })
}

export function getAgentProfitRunningBill (params) {
  return axios({
    url: `${api.agent}/running-bill`,
    method: 'get',
    params
  })
}

export function getAgentTeamList (params) {
  return axios({
    url: `${api.agent}/team`,
    method: 'get',
    responseType: params.hasOwnProperty('export') ? 'blob' : 'json', // 导出 下载
    params
  })
}

export function saveAgent (data) {
  return axios({
    url: api.agent + (data.hasOwnProperty('id') ? '/' + data.id : ''),
    method: data.hasOwnProperty('id') ? 'patch' : 'post',
    data
  })
}

export function adjustAgentBalance (data, option = {}) {
  return axios(
    Object.assign({
      url: `${api.agent}/balance`,
      method: 'patch',
      data
    }, option)
  )
}

export function updateAgentStatus (id, status) {
  return axios({
    url: `${api.agent}/${id}/status`,
    method: 'patch',
    data: {
      status: status
    }
  })
}

export function getAgentInfo (id) {
  return axios({
    url: `${api.agent}/${id}`,
    method: 'get'
  })
}

export function getAgentLabelList (params) {
  return axios({
    url: api.agentLabel,
    method: 'get',
    params
  })
}

export function deleteAgentLabel (id) {
  return axios({
    url: `${api.agentLabel}/${id}`,
    method: 'delete'
  })
}

export function saveAgentLabel (data) {
  return axios({
    url: api.agentLabel + (data.hasOwnProperty('id') ? '/' + data.id : ''),
    method: data.hasOwnProperty('id') ? 'patch' : 'post',
    data
  })
}

export function getRewardSettings () {
  return axios({
    url: `${api.agent}/reward-setting/table`,
    method: 'get'
  })
}

export function updateRewardSettings (data) {
  return axios({
    url: `${api.agent}/reward-setting/table/${data.id}`,
    method: 'patch',
    data
  })
}

export function adjustAgentDirectInviter (id, data) {
  return axios({
    url: `${api.agent}/${id}/direct-inviter`,
    method: 'patch',
    data
  })
}
